//
//  Hexagon.swift
//  AppleDemo
//
//  Created by Just 花语 on 2025/10/31.
//
import SwiftUI
struct Hexagon<Content: View>: View{
    private let borderWidth = 2.0
    var layout: HexagonLayout = .large
    var moment: Moment? = nil
    var borderColor: Color = .ember
    var size: CGFloat = 350
    @ViewBuilder var content: () -> Content
    var body: some View{
        ZStack{
            if let background = moment?.image{
                Image(uiImage: background)
                    .resizable()
                    .scaledToFill()
            }
            content()
                .frame(width: layout.size, height: layout.size)
        }
        .mask{
            Image(systemName: "hexagon.fill")
                .resizable()
                .aspectRatio(contentMode: .fit)
                .frame(width: layout.size - borderWidth, height: layout.size - borderWidth)
        }
        .background{
            Image(systemName: "hexagon")
                .resizable()
                .aspectRatio(contentMode: .fit)
                .frame(width: layout.size, height: layout.size)
                .foregroundStyle(borderColor)
                
        }
        .frame(width: layout.size, height: layout.size)
    }
}

#Preview{
    Hexagon(moment:Moment.imageSample){
        Text(Moment.imageSample.title)
            .foregroundStyle(Color.white)
    }
    .sampleDataContainer()
}
